function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { DoubleLeftOutlined, DoubleRightOutlined, LeftOutlined, RightOutlined } from '@ant-design/icons';
import { Button } from 'antd';
import { useExtendRef } from "../../../../util";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var buttonStyle = {
  size: 'small',
  style: {
    display: 'block',
    width: 30,
    margin: 8
  }
};
/**
 * 穿梭按钮
 * @param props
 * @constructor
 */
export default function ShuttleButtons(props) {
  var getRowKey = props.getRowKey,
    defaultAddResult = props.addResult,
    defaultRemoveResult = props.removeResult,
    getActiveTable = props.getActiveTable,
    getResultTable = props.getResultTable,
    outRef = props.outRef,
    _props$hasSelectAll = props.hasSelectAll,
    hasSelectAll = _props$hasSelectAll === void 0 ? true : _props$hasSelectAll,
    _props$isHorizontal = props.isHorizontal,
    isHorizontal = _props$isHorizontal === void 0 ? false : _props$isHorizontal,
    rowDisable = props.rowDisable,
    subRowDisable = props.subRowDisable;
  var addResult = defaultAddResult || function (values) {
    var selected = [];
    var existValues = getResultTable().getRows().map(function (r) {
      return getRowKey(r);
    });
    values.forEach(function (value) {
      if (existValues.indexOf(getRowKey(value)) === -1) {
        var newVal = JSON.parse(JSON.stringify(value));
        selected.push(newVal);
      }
    });
    getResultTable().addRows(selected);
  };
  var removeResult = defaultRemoveResult || function (indexes) {
    if (indexes === undefined) {
      var initData = getResultTable().getData().filter(function (x) {
        return subRowDisable(x);
      });
      getResultTable().setDataSource(initData);
    } else {
      getResultTable().deleteRows(indexes);
    }
  };
  useExtendRef(outRef, {
    toLeft: removeResult,
    toRight: addResult
  });
  buttonStyle.style.transform = isHorizontal ? 'rotate(90deg)' : 'rotate(0deg)';
  return /*#__PURE__*/_jsxs("div", {
    style: {
      display: 'flex',
      alignItems: 'center',
      justifyContent: 'center',
      flexDirection: isHorizontal ? 'row' : 'column'
    },
    children: [/*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonStyle), {}, {
      icon: /*#__PURE__*/_jsx(RightOutlined, {}),
      onClick: function onClick() {
        return addResult(getActiveTable().getSelectedData());
      }
    })), hasSelectAll && /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonStyle), {}, {
      icon: /*#__PURE__*/_jsx(DoubleRightOutlined, {}),
      onClick: function onClick() {
        return addResult(getActiveTable().getRows().filter(function (x) {
          return !rowDisable(x);
        }));
      }
    })), /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonStyle), {}, {
      icon: /*#__PURE__*/_jsx(LeftOutlined, {}),
      onClick: function onClick() {
        return removeResult(getResultTable().getSelectedIndexes());
      }
    })), hasSelectAll && /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonStyle), {}, {
      icon: /*#__PURE__*/_jsx(DoubleLeftOutlined, {}),
      onClick: function onClick() {
        return removeResult();
      }
    }))]
  });
}